package com.powerwyx.shortlink.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.powerwyx.shortlink.admin.common.convention.result.Result;
import com.powerwyx.shortlink.admin.common.convention.result.Results;
import com.powerwyx.shortlink.admin.remote.ShortLinkActualRemoteService;
import com.powerwyx.shortlink.admin.remote.dto.RecycleBinRecoverDTO;
import com.powerwyx.shortlink.admin.remote.dto.RecycleBinRemoveDTO;
import com.powerwyx.shortlink.admin.remote.dto.RecycleBinSaveDTO;
import com.powerwyx.shortlink.admin.remote.dto.ShortLinkRecycleBinPageDTO;
import com.powerwyx.shortlink.admin.remote.vo.ShortLinkPageVO;
import com.powerwyx.shortlink.admin.service.RecycleBinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 王艺锡
 * @version 1.0
 */
@RestController
public class RecycleBinController {
    @Autowired
    private RecycleBinService recycleBinService;

    @Autowired
    private ShortLinkActualRemoteService shortLinkActualRemoteService;

    /**
     * 添加短链接至回收站
     *
     * @param recycleBinSaveDTO
     * @return
     */
    @PostMapping("/api/shortlink/admin/v1/recyclebin/save")
    public Result<Void> saveRecycleBin(@RequestBody RecycleBinSaveDTO recycleBinSaveDTO) {
        shortLinkActualRemoteService.saveRecycleBin(recycleBinSaveDTO);
        return Results.success();
    }


    /**
     * 将短链接从回收站移出
     * @param recycleBinRecoverDTO
     * @return
     */
    @PostMapping("/api/shortlink/admin/v1/recyclebin/recover")
    public Result<Void> recoverRecycleBin(@RequestBody RecycleBinRecoverDTO recycleBinRecoverDTO){
        shortLinkActualRemoteService.recoverRecycleBin(recycleBinRecoverDTO);
        return Results.success();
    }




    /**
     * 删除回收站短链接
     * @param recycleBinRemoveDTO
     * @return
     */
    @PostMapping("/api/shortlink/admin/v1/recyclebin/remove")
    public Result<Void> removeRecycleBin(@RequestBody RecycleBinRemoveDTO recycleBinRemoveDTO){
        shortLinkActualRemoteService.removeRecycleBin(recycleBinRemoveDTO);
        return Results.success();
    }


    /**
     * 分页查询回收站中的短链接
     *
     * @param shortLinkRecycleBinPageDTO
     * @return
     */
    @GetMapping("/api/shortlink/admin/v1/recyclebin/page")
    public Result<Page<ShortLinkPageVO>> shortLinkRecycleBinPage(ShortLinkRecycleBinPageDTO shortLinkRecycleBinPageDTO) {
        return recycleBinService.shortLinkRecycleBinPage(shortLinkRecycleBinPageDTO);
    }

}
